﻿using Company.Share.Prism;
using System.IO;
using System.IO.Pipes;
using System.Text;
using System.Windows.Shapes;
using System.Xml.Serialization;

namespace Company.Main.ViewModels
{
    public class IOViewModel : BindableBase
    {
        private bool isInputButtonChecked;

        public bool IsInputButtonChecked
        {
            get { return isInputButtonChecked; }
            set { isInputButtonChecked = value; RaisePropertyChanged(); }
        }
        private bool isOutputButtonChecked;

        public bool IsOutputButtonChecked
        {
            get { return isOutputButtonChecked; }
            set { isOutputButtonChecked = value; RaisePropertyChanged(); }
        }

        public DelegateCommand<object> IOContentNavigateCommand { get;}
        public IModuleManager ModuleManager { get; }
        public IRegionManager RegionManager { get; }
        public IOViewModel(IModuleManager moduleManager, IRegionManager regionManager)
        {
            ModuleManager = moduleManager;
            RegionManager = regionManager;
            IOContentNavigateCommand = new DelegateCommand<object>(IOContentNavigate);
            // 需要提前初始化
            RegionManager.RequestNavigate(RegionNames.IORegion, ViewNames.DigitalInputView);
            RegionManager.RequestNavigate(RegionNames.IORegion, ViewNames.DigitalOutputView);
        }
        /// <summary>
        /// IOView界面导航
        /// </summary>
        /// <param name="obj"></param>
        private void IOContentNavigate(object obj)
        {
            var viewName = obj as string;
            if (viewName == null) return;
            switch (viewName)
            {
                case ViewNames.DigitalInputView:
                    RegionManager.RequestNavigate(RegionNames.IORegion, ViewNames.DigitalInputView);
                    IsInputButtonChecked = true;
                    IsOutputButtonChecked = false;
                    break;
                case ViewNames.DigitalOutputView:
                    RegionManager.RequestNavigate(RegionNames.IORegion, ViewNames.DigitalOutputView);
                    IsInputButtonChecked = false;
                    IsOutputButtonChecked = true;
                    break;
                default:
                    RegionManager.RequestNavigate(RegionNames.IORegion, ViewNames.DigitalInputView);
                    IsInputButtonChecked = true;
                    IsOutputButtonChecked = false;
                    break;
            }
        }
    }
}
